﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MillerApp.DataContract.MillerDB;
using MillerApp.DataAccess.MillerDB;
using MillerApp.UserControls;
using MillerApp.CommonLib.Utility;

namespace MillerApp.Stock.Query
{
    public partial class StockQuery : Form
    {
        public StockQuery()
        {
            InitializeComponent();
        }

        private void StockQuery_Load(object sender, EventArgs e)
        {
            this.dataGridView1.AutoGenerateColumns = false;
            this.queryActions1.PagerControl = this.dataPagerControl1;
            this.queryActions1.OnQueryingData += new QueryingDataEventHandler(queryActions1_OnQueryingData);
            this.queryActions1.GetConditions += new GetStringDelegate(queryActions1_GetConditions);
        }

        string queryActions1_GetConditions()
        {
            string conditions = string.Empty;
            if (string.IsNullOrEmpty(txtTypeName.Text) == false)
            {
                conditions += " and (secCode like '%" + txtTypeName.Text + "%' or secshortname like '%" + txtTypeName.Text + "%' or pysx like '%" + txtTypeName.Text + "%')";
            }
            if (chkBoxTradeDate.Checked)
            {
                conditions += " and seccode not in (SELECT seccode	FROM stockquotations	where tradeday='" + dpkerStart.Value.Date.ToString("yyyy-MM-dd") + "' )";
            }
            if (chkStatus.Checked==false)
            {
                conditions += " and status<>2 ";
            }
            return conditions;
        }

        void queryActions1_OnQueryingData(string conditions, string sortExpression, int pageIndex, int pageSize)
        {
            int recordCount = 0;
            List<SecurityEntity> list = SecurityManager.GetSecuritysByCond(conditions, sortExpression, pageIndex, pageSize, out recordCount);
            this.dataGridView1.DataSource = list;
            this.queryActions1.RecorderCount = recordCount;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageWindow w = new MessageWindow();
            w.Show();
        }

    }
}
